package com.idrive.listener;

import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.os.Bundle;
import android.widget.Toast;

import com.idrive.database.dao.LocationDataDao;
import com.idrive.database.dto.LocationData;

public class PathTrackerListener implements LocationListener {

	private Context context;

	public PathTrackerListener(Context context) {
		this.context = context;

	}

	public void onLocationChanged(Location location) {
		try {
			LocationData data = new LocationData();
			data.setTime(location.getTime());
			data.setLatitude(location.getLatitude());
			data.setLongitude(location.getLongitude());
			data.setGroupId(LocationData.LOCATION_UUID);

			LocationDataDao dao = new LocationDataDao(context);
			dao.addLocation(data);
			//dao.deleteOldRecords();
		} catch (Exception exception) {
			exception.printStackTrace();
			Toast.makeText(context, exception.getMessage(), Toast.LENGTH_LONG).show();
		}
	}

	public void onProviderDisabled(String arg0) {

	}

	public void onProviderEnabled(String arg0) {

	}

	public void onStatusChanged(String arg0, int arg1, Bundle arg2) {

	}

}
